package com.monster.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.monster.vo.ReportSetmemlVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface ReportMapper extends BaseMapper {

    @Select("select  count(tm.id)  as membercounts,CONCAT(rd.fyear,'-',rd.fmonth) as yearsandmonth " +
            "from  rpt_date  rd , t_member tm " +
            "where  rd.fdate = tm.REGTIME " +
            "and fyear =year(now()) " +
            " group by rd.fmonth")
    List<Map> findMemberCountOfYearsAndMonth();

    @Select("select count(ts.id) as value ,ts.name  " +
            "from   t_order tor, t_setmeal ts "+
            "where  tor.setmeal_id  = ts.id " +
            " group by ts.id")
    List<Map> setmealProportion();

    @Select("select count(1) " +
            "from t_member tm " +
            "where tm.REGTIME = day(now());")
    int todayNewMember();

    @Select("select count(1) from t_member")
    int totalMember();

    @Select("select count(1) " +
            "from t_member tm " +
            "where tm.REGTIME = week(now());")
    int thisWeekNewMember();

    @Select("select count(1) " +
            "from t_member tm " +
            "where tm.REGTIME = month(now());")
    int thisMonthMember();


    @Select("select count(1) " +
            "from t_order " +
            "where ORDERDATE = day(now())")
    int todayOrderNumber();

    @Select("select count(1) " +
            "from t_order " +
            "where ORDERDATE = day(now()) and ORDERSTATUS ='到诊'")
    int todayVisitsNumber();

    @Select("select count(1) " +
            "from t_order " +
            "where ORDERDATE = week(now()) and ORDERSTATUS ='到诊'")
    int thisWeekVisitsNumber();

    @Select("select count(1) " +
            "from t_order " +
            "where ORDERDATE = week(now())")
    int thisWeekOrderNumber();

    @Select("select count(1) " +
            "from t_order " +
            "where ORDERDATE = month(now())")
    int thisMonthOrderNumber();

    @Select("select count(1) " +
            "from t_order " +
            "where ORDERDATE = month(now()) and ORDERSTATUS ='到诊'")
    int thisMonthVisitsNumber();

    @Select("select ts.name ,count(tor.SETMEAL_ID) as setmealCount ,ts.REMARK as remark " +
            "from t_setmeal ts, t_order tor " +
            "where ts.id = tor.SETMEAL_ID " +
            "group by ts.id")
    List<ReportSetmemlVo> findHotSetmeal();


    @Select("select count(1) " +
            "from  t_order")
    int findAllOrder();

}
